<!--{template pc/frame/header_simple_start}-->
<script type="text/javascript" src="{MOD_PATH}/js/pc/plug/sortable.min.js?{VERHASH}"></script>
<style type="text/css">
	.el-table{
		color: var(--content-text);
		background: transparent;
	}
	.el-table thead{
		color: var(--content-textHover);
	}
	.el-table .el-table__empty-text{
		color: var(--content-text);
	}
	.el-table .operation{
		overflow: hidden;
		white-space: nowrap;
		text-align: right;
	}
	.el-table .link{
		font-size: 20px;
		display: inline-block;
		vertical-align: bottom;
		color: var(--leftTreeColor);
	}
	.el-table .operation .icon{
		font-size: 18px;
		display: inline-block;
		margin-right: 8px;
		cursor: pointer;
	}
	/* .el-table .operation .icon:last-child{
		margin-right:0;
	} */
	.el-table .operation .icon:hover{
		color: var(--content-textHover);
	}
	.el-table .operation .icon.loading{
		animation: rotating 2s linear infinite;
	}
	.Import-dialog{
		display: flex;
		flex-direction: column;
		margin: 0 !important;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%,-50%);
		/* height: 180px; */
		max-height: calc(100% - 200px);
		max-width: calc(100% - 30px);
	}
	.Import-dialog .el-dialog__header{
		text-align: left;
		padding: 15px;
		padding-bottom: 10px;
	}
	.Import-dialog .el-dialog__body{
		padding: 10px 15px;
		color: var(--header-text);
	}
	.notes-box{
		padding: 24px 10px;
		color: var(--content-text);
	}
	.notes-box .block{
		font-size: 14px;
		overflow: hidden;
		margin-bottom: 8px;
	}
	.notes-box .block .text{
		float: left;
		width: 80px;
	}
	.notes-box .block .message{
		float: left;
		width: calc(100% - 80px);
	}
</style>
<!--{template pc/frame/header_simple_end}-->
<div id="dzzoffice">
	<el-container>
		<el-header height="70px" style="padding: 0;z-index: 10;">
			<div id="top_header" style="padding: 4px 16px;">
				<div class="header-content">
					<div class="h-left">
						<a href="{MOD_URL}">
							<el-image src="dzz/pichome/image/library/library.png?{VERHASH}" fit="contain"></el-image>
							<span class="text">库设置</span>
						</a>
					</div>
					<div class="h-center">
					</div>
					<div class="h-right" style="overflow: hidden;">
						<el-button type="primary" size="small"  icon="el-icon-circle-plus-outline" @click="CreateNewLubrary" style="float: left;">新建库</el-button>
						<div class="r-option" style="margin-left: 8px;display: inline-block;">
							<el-dropdown v-cloak trigger="click" @command="handleavatar">
								<div id="dzz_avatar_img" class="small">{eval echo avatar_block($_G[uid]);} </div>
								<el-dropdown-menu slot="dropdown" style="width: 165px;">

									<el-dropdown-item command="personal">个人设置</el-dropdown-item>
									<el-dropdown-item command="help">帮助文档</el-dropdown-item>
									<el-dropdown-item command="problem">问题反馈</el-dropdown-item>
									<el-divider></el-divider>
									<el-dropdown-item command="setting">站点设置</el-dropdown-item>
									<el-dropdown-item command="library">库设置</el-dropdown-item>
									<el-dropdown-item command="system">系统工具</el-dropdown-item>
									<el-divider></el-divider>
									<el-dropdown-item command="about">关于PicHome</el-dropdown-item>
									<el-dropdown-item command="OutLogin">退出站点</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</div>
					</div>
				</div>
			</div>
		</el-header>
		<el-main>
			<div class="page-content">
				<el-scrollbar class="page-component__scroll">
					<div class="content" style="padding: 26px 16px;">
						<el-table
							v-loading="loading"
						    :data="tableData"
							row-key="appid"
							stripe
						    style="width: 100%">
						    <el-table-column
								show-overflow-tooltip
						        label="库名称">
								<template slot-scope="scope">
									<template v-if="parseInt(scope.row.connect) == 1">
										<a :href="'#appid='+scope.row.appid" target="_blank" style="color: var(--content-text);text-decoration: none;">
											<template v-if="parseInt(scope.row.type)==1">
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/file.png"
												    fit="contain"></el-image>
											</template>
											<template v-else-if="parseInt(scope.row.type)==2">
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/billfish.png"
												    fit="contain"></el-image>
											</template>
											<template v-else>
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/eagle.png"
												    fit="contain"></el-image>
											</template>
											<span style="margin-left: 8px;">{{ scope.row.appname }}</span>
										</a>
									</template>
									<template v-else>
										<div style="display: inline-block;color: var(--content-text);">
											<template v-if="parseInt(scope.row.type)==1">
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/file.png"
												    fit="contain"></el-image>
											</template>
											<template v-else-if="parseInt(scope.row.type)==2">
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/billfish.png"
												    fit="contain"></el-image>
											</template>
											<template v-else>
												<el-image
												    style="width: 24px; height: 24px;vertical-align: top;"
												    src="dzz/pichome/image/library/eagle.png"
												    fit="contain"></el-image>
											</template>
											<span style="margin-left: 8px;">{{ scope.row.appname }}</span>
										</div>
									</template>
								</template>
						    </el-table-column>
							<el-table-column
								show-overflow-tooltip
							    label="位置">
								<template slot-scope="scope">
									{{ decodeURI(scope.row.path) }}
								</template>
							</el-table-column>
							<el-table-column
							    prop="filenum"
								width="120"
								align="center"
							    label="连接状态">
								<template slot-scope="scope">
									<template v-if="parseInt(scope.row.connect) == 1">
										<i class="link ri-link-m"></i>
										<span style="color: var(--leftTreeColor);">连接正常</span>
									</template>
									<template v-else>
										<i class="link ri-link-unlink-m" style="color: #e6a23c;"></i>
										<span style="color: #e6a23c;">连接中断</span>
									</template>
								</template>
							</el-table-column>
							<el-table-column
							    prop="filenum"
								width="150"
								align="center"
							    label="文件数">
							</el-table-column>
							<el-table-column
								width="150"
								align="center"
							    label="导入数">
								<template slot-scope="scope">
									<template v-if="parseInt(scope.row.state)==0">{{scope.row.filenum}}</template>
									<template v-else-if="parseInt(scope.row.state)==1">0%</template>
									<template v-else-if="parseInt(scope.row.state)==2">{{scope.row.percent}}%</template>
									<template v-else-if="parseInt(scope.row.state)==3">{{scope.row.percent}}%</template>
									<template v-else>{{scope.row.filenum}}</template>
								</template>
							</el-table-column>
							<el-table-column
								width="120"
								align="center"
							    label="状态">
								<template slot-scope="scope">
									<template v-if="parseInt(scope.row.state)==0">未导入</template>
									<template v-else-if="parseInt(scope.row.state)==1">准备中...</template>
									<template v-else-if="parseInt(scope.row.state)==2">导入中...</template>
									<template v-else-if="parseInt(scope.row.state)==3">校验中...</template>
									<template v-else-if="parseInt(scope.row.state)==-1">更新失败</template>
									<template v-else>完成</template>
								</template>
							</el-table-column>
							<el-table-column
								width="120"
								align="center"
							    label="缩略图">
								<template slot-scope="scope">
									<template v-if="parseInt(scope.row.getinfonum)">
										{{scope.row.getinfonum}}
									</template>
									<template v-else>——</template>
								</template>
							</el-table-column>
							<el-table-column
							    label="操作"
								align="center"
								width="180">
								<template slot-scope="scope">
									<div class="operation">
										<template v-if="parseInt(scope.row.connect) == 1">
											<el-tooltip :enterable="false" effect="dark" content="更新" placement="top">
												<i class="icon ri-refresh-line" style="vertical-align: sub;margin-right: 0;" :class="{loading:parseInt(scope.row.state)==1||parseInt(scope.row.state)==2||parseInt(scope.row.state)==3}" @click="handleRefreshClick(scope.row.appid)"></i>
												
											</el-tooltip>
											
											<el-dropdown @command="handleRefresh"  trigger="click">
												<i class="icon el-icon-caret-bottom"style="font-size: 16px;"></i>
												<el-dropdown-menu slot="dropdown">
													<el-dropdown-item :command="handleRefreshVal(0,scope.row.appid)">正常更新</el-dropdown-item>
													<el-dropdown-item :command="handleRefreshVal(1,scope.row.appid)">校验修正更新</el-dropdown-item>
												</el-dropdown-menu>
											</el-dropdown>
										</template>
										<el-tooltip :enterable="false" effect="dark" content="设置" placement="top">
											<i class="icon el-icon-setting" @click="handleSetting(scope.row.appid,scope.row.appname)"></i>
										</el-tooltip>
										
										<el-popconfirm title="确定删除该库？确定后无法恢复" @Confirm="deleteLibrary(scope.row.appid)">
											<el-tooltip slot="reference" :enterable="false" effect="dark" content="删除" placement="top">
											    <i class="icon el-icon-delete"></i>
											</el-tooltip>
										</el-popconfirm>
										<el-tooltip :enterable="false" effect="dark" content="拖动排序" placement="top">
										    <i class="icon el-icon-rank icon-rank" style="margin-right: 0;"></i>
										</el-tooltip>
									</div>
								</template>
							</el-table-column>
						</el-table>
						<style type="text/css">
							
						</style>
						<div class="notes-box">
							<p class="title" style="padding: 8px 0;">注释：</p>
							<div class="block">
								<div class="text">库图标：</div>
								<div class="message" style="float: left;">
									<div style="display: inline-block;">
										<el-image
										    style="width: 20px; height: 20px;vertical-align: top;margin-right: 5px;"
										    src="dzz/pichome/image/library/file.png"
										    fit="contain"></el-image>
										    普通目录
									</div>
									<div style="display: inline-block;margin-left: 8px;">
										<el-image
										    style="width: 20px; height: 20px;vertical-align: top;margin-right: 5px;"
										    src="dzz/pichome/image/library/eagle.png"
										    fit="contain"></el-image>
										Eagle库
									</div>
									<div style="display: inline-block;margin-left: 8px;">
										<el-image
										    style="width: 22px; height: 22px;vertical-align: middle;margin-right: 5px;"
										    src="dzz/pichome/image/library/billfish.png"
										    fit="contain"></el-image>
										Billfish
									</div>
								</div>
							</div>
							<div class="block">
								<div class="text">连接状态：</div>
								
								<div class="message">当连接状态为<span style="color: #e6a23c;">连接中断</span>时，库内容将不会在页面中显示。可能原因为库目录被移动或者删除，如果是移动了库目录位置，可以在设置中修改库目录位置。</div>
							</div>
							<div class="block">
								<div class="text">转缩略图：</div>
								<div class="message">
									对于图片文件比较大时，为图片转换缩略图会提高列表页面的显示速度。<el-link style="vertical-align: bottom;" type="primary" :underline="false" href="{MOD_URL}&op=storagesetting">开启方法是在站点设置中开启</el-link>图片处理，媒体处理，文档处理。只有普通目录会需要转缩略图，其他软件的库目录不需要转缩略图
								</div>
							</div>
							<div class="block">
								<div class="text">更新功能：</div>
								<div class="message">正常更新用于平时正常更新，一般更新会忽略已有数据，更新速度快。<br>校验修正更新，当之前更新数据发现有错误信息时，可以尝试校验修正更新。会强制校验已有数据，对已有数据如果是有错误的信息进行更正。更新速度会与首次更新一样，更新速度慢一些。</div>
							</div>
						</div>
					</div>	
				</el-scrollbar>
			</div>
		</el-main>
		<el-dialog
			title="选择目录"
			:close-on-click-modal="false"
			:visible.sync="catalogue.dialogVisible"
			@open="cataloguedialogOpen">
			<div style="padding-bottom:16px">
				<span style="color: var(--header-text);">库类型：</span>
				<el-radio-group v-model="catalogue.type" :disabled="catalogue.dialogtype=='add'?false:true">
					<el-radio label="0">Eagle库</el-radio>
					<el-radio label="2">billfish</el-radio>
					<el-radio label="1">普通目录</el-radio>
				</el-radio-group>
			</div>
			<div style="padding-bottom:16px">
				<el-input placeholder="输入快捷路径" clearable v-model="catalogue.search" @input="cataloguesearch" class="input-with-select">
				    <el-select v-model="catalogue.select" slot="append" placeholder="快捷路径" clearable style="width: 120px;" @change="catalogueselect">
						<template v-for="(item,index) in catalogue.selectData">
							<template v-if="item.type == 1">
								<el-option label="站点Library目录" :value="index" :key="index"></el-option>
							</template>
							<template v-else>
								<el-option :label="item.path" :value="index" :key="index"></el-option>
							</template>
						</template>
						
				    </el-select>
				</el-input>
			</div>
			<div style="color: var(--header-text);">路径选择：</div>
			<el-scrollbar class="h350">
				<div style="padding-left: 16px;">
					<el-tree
						class="border"
						highlight-current 
						:load="LoadNodeTree" 
						lazy 
						node-key="id"
						ref="tree_catalogue"
						indent="0"
						accordion
						@current-change="TreeCurrentChange">
						<span class="custom-tree-node" slot-scope="{ node, data }" style="white-space: nowrap;text-overflow: ellipsis;overflow: hidden;">
							<span>
								<i class="ri-folder-2-line"></i><span style="margin-left: 6px;">{{ node.label }}</span>
							</span>              
						</span>
					</el-tree>
				</div>
			</el-scrollbar>
			<div style="color: var(--header-text);padding-top: 16px;">已选择路径：{{catalogue.showVal}}</div>	
			<span slot="footer" class="dialog-footer">
				<el-button @click="catalogue.dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="catalogueSubmit">确 定</el-button>
			</span>
		</el-dialog>
		<el-dialog
			custom-class="Import-dialog"
			title="提示"
			:visible.sync="ImportDataVisible"
			:close-on-click-modal="false"
			:show-close="false"
			width="420px">
			<div class="el-message-box__container"><div class="el-message-box__status el-icon-warning"></div><div class="el-message-box__message"><p>系统检测该目录为eagle库，只能作为Eagle导入。</p></div></div>
			<span slot="footer" class="dialog-footer">
				<el-button style="float: left;" @click="ImportDataVisible = false" size="small">取消</el-button>
				<el-button type="warning" @click="ImportDataDialogClick('eagle')" size="small">作为Eagle库导入</el-button>
		  </span>
		</el-dialog>
		<el-dialog :title="dialog.title" :visible.sync="dialog.Visible" :close-on-click-modal="false" :show-close="formdta.loading?false:true">
			<el-form :model="formdta" label-width="140px">
	<!-- 					<el-form-item label="开放权限：">
					<el-radio-group v-model="formdta.personal">
						<el-radio :label="0">公开</el-radio>
						<el-radio :label="1">私有</el-radio>
					</el-radio-group>
				</el-form-item> -->
				<el-form-item label="库名称：">
				    <el-input v-model="formdta.appname"></el-input>
				  </el-form-item>
				<el-form-item label="库位置：">
				    <el-input v-model="formdta.path" readonly style="border: 0;">
						<i slot="suffix" style="cursor: pointer;" class="el-input__icon el-icon-edit" @click="FormdtaPathClick"></i>
					</el-input>
				  </el-form-item>
				<el-form-item label="开放分享：">
					<el-switch v-model="formdta.share" active-value="1" inactive-value="0"></el-switch>
				</el-form-item>
				<el-form-item label="开放下载：">
					  <el-switch v-model="formdta.download" active-value="1" inactive-value="0"></el-switch>
				</el-form-item>
				<template v-if="parseInt(formdta.eagle)==1">
					<el-form-item label="允许导入文件：">
						<el-input type="textarea" v-model="formdta.allowext"></el-input>
						<p class="tipTxt">多个使用英文 " , " 隔开。1、"*.png" 代表所有png文件，2、"风景*.jpg"代表所有风景开头的png文件</p>
					</el-form-item>
					<el-form-item label="禁止导入文件：">
						<el-input type="textarea" v-model="formdta.notallowext"></el-input>
						<p class="tipTxt">多个使用英文 " , " 隔开。1、"*.png" 代表所有png文件，2、"风景*.jpg"代表所有风景开头的png文件</p>
					</el-form-item>
					<!-- <el-form-item label="开启缩略图转换：">
						<el-switch v-model="formdta.getinfo" active-value="1" inactive-value="0"></el-switch>
						<p class="tipTxt">缩略图转换需要较长时间，转换时会增加会增加服务器CPU与内存占用，转换缩略图对于大尺寸图片的列表显示速度有大幅度提升</p>
					</el-form-item> -->
				</template>
				
			</el-form>
			<div slot="footer" class="dialog-footer">
<!-- 				<el-popconfirm title="确定删除该库？确定后无法恢复" @Confirm="deleteLibrary">
					<el-button slot="reference" style="float: left;">删除</el-button>
				</el-popconfirm> -->
				<el-button @click="dialog.Visible = false" :disabled="formdta.loading">取 消</el-button>
				<el-button type="primary" @click="handleSubmit" :loading="formdta.loading">确 定</el-button>
			</div>
		</el-dialog>
	</el-container>
</div>
<!-- 0未导入,1准备中，2导入中,3校验中,4完成 -->
<script type="text/javascript">
	new Vue({
		el: '#dzzoffice',
		data() {
			return {
				loading:true,
				tableData:[],
				dialog:{
					title:'',
					Visible:false,
				},
				formdta:{
					appname:'',
					loading:false,
					appid:'',
					path:'',
					share:'0',
					getinfo:'0',
					download:'0',
					eagle:0,
					allowext:'',
					notallowext:'',
					charset:'',
					
				},
				catalogue:{
					appid:'',
					dialogtype:'',
					search:'',
					defaultsearch:'',
					searchStatus:false,
					select:'',
					type:'0',
					parentresolve:'',
					parentnode:'',
					selectData:[],
					nodeId:0,
					parent:[],
					dialogVisible:false,
					defaultVal:[],
					showVal:'',
					charset:'utf8',
					force:0,
					gettype:null
				},
				ImportDataVisible:false,
				getinfonumNum:0,
				GetFetachNum:0,
				GetFetachAppids:[],
			}
		},
		watch:{
		},
		created() {
			this.GetData();
			this.GetCatalogueSelect();
		},
		methods:{
			
			FormdtaPathClick(){
				this.catalogue.dialogtype = 'setting';
				this.catalogue.type = this.formdta.type;
				this.catalogue.appid = this.formdta.appid;
				var showVal = this.formdta.path;
				showVal = showVal.split('/');
				showVal.pop();
				var newshowVal = showVal.join('/');
				this.catalogue.showVal = '';
				this.catalogue.search = newshowVal;
				this.catalogue.defaultsearch = newshowVal;
				this.catalogue.searchStatus = true;
				this.catalogue.charset = this.formdta.charset;
				this.dialog.Visible = false;
				this.catalogue.dialogVisible = true;
			},
			CreateNewLubrary(){
				this.catalogue.dialogtype = 'add';
				this.catalogue.dialogVisible = true;
			},
			TableSortable(){
				var _this = this;
				var tbody = document.querySelector('.el-table__body-wrapper tbody');
				Sortable.create(tbody, {
					draggable: ".el-table__row",
					handle:".icon-rank",
					onEnd ({ newIndex, oldIndex }) {
						var currRow = _this.tableData.splice(oldIndex, 1)[0];
						_this.tableData.splice(newIndex, 0, currRow);
						var appids = [];
						for(var i in _this.tableData){
							var item = _this.tableData[i];
							appids.push(item.appid);
						}
						appids = appids.join(',');
						_this.TableSortableSubmit(appids);
					}
				});
			},
			TableSortableSubmit(appids){
				var self = this;
				$.post(MOD_URL+'&op=library&operation=sort',{
					settingsubmit:true,
					formhash:'{FORMHASH}',
					appids:appids
				},function(data){
					if(data.success){
						self.$message({
							type:'success',
							message:'排序成功'
						});
					}else{
						self.$message.error('排序失败');
					}
				},'json');
			},
			handleSubmit(){
				var self = this;
				self.formdta.loading = true;
				var param = {
					settingsubmit:true,
					formhash:'{FORMHASH}',
					appid:self.formdta.appid,
					appname:self.formdta.appname,
					getinfo:self.formdta.getinfo,
					share:self.formdta.share,
					download:self.formdta.download,
					allowext:self.formdta.allowext,
					notallowext:self.formdta.notallowext,
				};
				$.post(MOD_URL+'&op=library&operation=fetch',param,function(data){
					self.dialog.Visible = false;
					if(data.success){
						for(var x in self.tableData){
							if(self.tableData[x].appid == self.formdta.appid){
								self.tableData[x].getinfo = self.formdta.getinfo;
								self.tableData[x].appname = self.formdta.appname;
							}
						}
						self.tableDataForEach();
						self.$message({
							type:'success',
							message:'设置成功'
						});
					}else{
						self.$message.error('设置失败');
					}
					self.formdta.loading = false;
				},'json');
			},
			handleSetting(appid,title){
				var self = this;
				this.dialog.title = '设置'+title+'库';
				$.post(MOD_URL+'&op=library&operation=fetch',{
					appid:appid
				},function(data){
					if(data.success){
						var showVal = data.data.convertpath.replace(/\\/g,"/");
						self.dialog.Visible = true;
						self.formdta = {
							appid:appid,
							appname:data.data.appname,
							path:showVal,
							getinfo:data.data.getinfo,
							share:data.data.share,
							download:data.data.download,
							charset:data.data.charset,
							eagle:parseInt(data.data.type),
							allowext:data.data.allowext,
							notallowext:data.data.notallowext,
							loading:false
						};
					}else{
						self.$message.error('数据获取失败');
					}
				},'json');
			},
			cataloguedialogOpen(){
				if(this.catalogue.dialogtype == 'setting'){
					return false;
				}
				var dzzroot = '$dzzroot';
				var defaultVal = [];
				var showVal = '';
				if(dzzroot){
					var str = dzzroot+'library';
					defaultVal = str.split('/');
					showVal = defaultVal.join('/');
				}
				
				this.catalogue.search = '';
				this.catalogue.defaultsearch = '';
				this.catalogue.searchStatus = '';
				this.catalogue.select = '';
				this.catalogue.type = '0';
				this.catalogue.nodeId = 0;
				this.catalogue.parent = [];
				this.catalogue.showVal = '';
				this.catalogue.charset = 'utf8';
				this.catalogue.force = 0;
				this.catalogue.gettype = 1;
				if(this.catalogue.parentnode){
					this.catalogue.parentnode.childNodes = []
					this.LoadNodeTree(this.catalogue.parentnode,this.catalogue.parentresolve);
				}
				
			},
			ImportDataDialogClick(type){
				if(type == 'eagle'){
					this.catalogue.type = 0;
				}else{
					this.catalogue.type = 1;
				}
				this.catalogue.force = 1;
				this.ImportDataVisible = false;
				this.catalogueSubmit();
			},
			catalogueselect(val){
				var self = this;
				var path = '';
				self.catalogue.gettype = null;
				if(self.catalogue.selectData[val]){
					self.catalogue.searchStatus = true;
					var item = self.catalogue.selectData[val];
					path = item.path;
					self.catalogue.charset = item.charset;
					self.catalogue.gettype = item.type;
				}else{
					for(var i in self.catalogue.selectData){
						if(self.catalogue.selectData[i].type==1){
							self.catalogue.charset = self.catalogue.selectData[i].charset;
							self.catalogue.gettype = self.catalogue.selectData[i].type;
						}
					}
					self.catalogue.searchStatus = false;
				}
				this.catalogue.defaultsearch = path;
				self.catalogue.search = path;
				self.catalogue.parentnode.childNodes = []
				this.LoadNodeTree(self.catalogue.parentnode,self.catalogue.parentresolve);
			},
			cataloguesearch:debounce(function(val){//输入
				var self = this;
				self.catalogue.select = '';
				if(val){
					self.catalogue.searchStatus = true;
				}else{ 
					for(var i in self.catalogue.selectData){
						if(self.catalogue.selectData[i].type == 1){
							self.catalogue.charset = self.catalogue.selectData[i].charset;
						}
					}
					self.catalogue.searchStatus = false;
				}
				this.catalogue.defaultsearch = val;
				self.catalogue.parentnode.childNodes = []
				this.LoadNodeTree(self.catalogue.parentnode,self.catalogue.parentresolve);
			},800),
			LoadNodeTree(node, resolve){
				var self = this;
				var param = {};
				var fparam = '';
				if(self.catalogue.searchStatus){
					if(node.level > 0){
						if(node.level > 1){
							self.catalogue.parent = [];
							this.GetTreeParens(node.parent);
							var oparam = self.catalogue.parent.reverse();
							fparam = oparam.join('/');
							fparam += '/'+node.data.label;
							param['path'] = self.catalogue.defaultsearch+'/'+fparam;
							
						}else{
							param['path'] = self.catalogue.defaultsearch+'/'+node.data.label;
						}
					}else{
						param['path'] = self.catalogue.search;
					}
					if(self.catalogue.gettype){
						param['gettype'] = self.catalogue.gettype;
					}
				}else{
					if(node.level > 0){
						if(node.level > 1){
							self.catalogue.parent = [];
							this.GetTreeParens(node.parent);
							var oparam = self.catalogue.parent.reverse();
							fparam = oparam.join('/');
							fparam += '/'+node.data.label;
							param['path'] = self.catalogue.defaultVal.join('/')+'/'+fparam;
							
						}else{
							param['path'] = self.catalogue.defaultVal.join('/')+'/'+node.data.label;
						}
						if(self.catalogue.gettype){
							param['gettype'] = self.catalogue.gettype;
						}
					}else{
						// param['path'] = self.catalogue.defaultVal.join('/');
						self.catalogue.showVal = self.catalogue.defaultVal.join('/');
					}
				}
				if(node.level == 0){
					self.catalogue.parentresolve = resolve;
					self.catalogue.parentnode = node;
				}else{
					param['charset'] = node.data && node.data.charset?node.data.charset:'';
				}
				$.post(MOD_URL+'&op=library&operation=getpath',param,function(data){
					var fdata = [];
					for(var i in data.data){
						self.catalogue.nodeId++;
						var item  = data.data[i];
						fdata.push({
							label:item.path,
							id:self.catalogue.nodeId,
							charset:item.charset
						});
					}
					if(self.catalogue.searchStatus){
						resolve(fdata);
						if(fdata.length){
							self.catalogue.showVal = self.catalogue.search;
						}
					}else{
						
						resolve(fdata);
					}
					
				},'json');
			},
			GetTreeParens(node){
				var self = this;
				var data = self.$refs.tree_catalogue.getNode(node);
				self.catalogue.parent.push(data.data.label);
				if(node.level > 1){
					self.GetTreeParens(node.parent);
				}
			},
			TreeCurrentChange(data,node){
				var self = this;
				self.catalogue.parent = [];
				var path = '';
				if(node.level>1){
					self.GetTreeParens(node.parent);
					var oparam = self.catalogue.parent.reverse();
					var fparam = oparam.join('/');
					path = fparam+'/'+data.label;
				}else{
					path = data.label;
				}
				if(self.catalogue.defaultsearch){
					self.catalogue.searchStatus = true;
					this.catalogue.showVal = self.catalogue.defaultsearch+'/'+path;
					this.catalogue.search = self.catalogue.defaultsearch+'/'+path;
				}else{
					self.catalogue.showVal = self.catalogue.defaultVal.join('/')+'/'+path;
					// self.catalogue.showVal = path;
					self.catalogue.searchStatus = false;
				}
				this.catalogue.charset = data.charset;
			},
			catalogueSubmit(){
				var self = this;
				if(!self.catalogue.showVal){
					self.$message.error('请选择路径');
					return false;
				}
				var url = MOD_URL+'&op=library&operation=addlibrary';
				if(this.catalogue.dialogtype == 'setting'){
					url = MOD_URL+'&op=library&operation=changePath';
					var param = {
						appid:self.catalogue.appid,
						path:self.catalogue.showVal,
						type:self.catalogue.type,
						gettype:self.catalogue.gettype,
						charset:self.catalogue.charset
					}
				}else{
					var param = {
						path:self.catalogue.showVal,
						type:self.catalogue.type,
						gettype:self.catalogue.gettype,
						charset:self.catalogue.charset
					}
				}
				
				if(self.catalogue.type == 1 && self.catalogue.force){
					param['force'] = 1;
				}
				$.post(url,param,function(data){
					if(data.tips){
						self.$message.error(data.tips);
						return false;
					}
					if(data.error){
						self.$message.error(data.error);
					}else{
						if(self.catalogue.dialogtype == 'setting'){
							// for(var a in self.tableData){
							// 	if(self.tableData[a].appid == param.appid){
							// 		self.tableData[a].path = param.path;
							// 	}
							// }
							// self.$message({
							// 	message: '修改成功',
							// 	type: 'success'
							// });
							window.location.reload();
						}else{
							self.$message({
								message: '添加成功',
								type: 'success'
							});
							var fdata = data.data;
							fdata['state'] = 0;
							fdata['filenum'] = 0;
							fdata['percent'] = 0;
							fdata['connect'] = 1;
							fdata['type'] = self.catalogue.type;
							fdata['getinfonum'] = 0;
							
							self.tableData.push(fdata);
						}
						
						self.catalogue.dialogVisible = false;
					}
					
				},'json');
			},
			deleteLibrary(appid){
				var self = this;
				$.post(MOD_URL+'&op=library&operation=dellibrary',{
					appid:appid
				},function(data){
					if(data.success){
						self.$message({
							type:'success',
							message:'删除成功'
						});
						var index = 0;
						for(var i in self.tableData){
							if(self.tableData[i].appid == appid){
								index = i;
							}
						}
						if(self.GetFetachAppids.indexOf(appid)>-1){
							self.GetFetachAppids.splice(self.GetFetachAppids.indexOf(appid),1);
						}
						self.tableData.splice(index,1);
					}else{
						self.$message.error('删除失败');
					}
				},'json');
			},
			GetData(){
				var self = this;
				$.post(MOD_URL+'&op=library&operation=getdata',function(data){
					self.tableData = data.data;
					self.loading = false;
					for(var i in self.tableData){
						if(parseInt(self.tableData[i].state) == 1 || parseInt(self.tableData[i].state) == 2 || parseInt(self.tableData[i].state) == 3){
							if(self.GetFetachAppids.indexOf(self.tableData[i].appid)<0){
								self.GetFetachAppids.push(self.tableData[i].appid);
							}
						}
						
					}
					if(self.GetFetachNum == 0){
						self.handleRefreshLoading();
					}
					self.tableDataForEach();
					self.$nextTick(function(){
						self.TableSortable();
					});
				},'json');
			},
			tableDataForEach(){
				var self = this;
				// var isInterval = false;
				
				// for(var i in self.tableData){
				// 	var item = self.tableData[i];
				// 	if(parseInt(item.state) == 4 && parseInt(item.type) == 1 && parseInt(item.getinfo) == 1 && parseInt(item.getinfonum)<parseInt(item.filenum)){
				// 		isInterval = true;
				// 		break;
				// 	}
				// }
				if(!self.getinfonumNum){
					self.getinfonumtime();
				}
			},
			getinfonumtime(){
				var self = this;
				self.getinfonumNum = 1;
				setTimeout(function(){
					$.get(MOD_URL+'&op=library&operation=getinfonum',function(data){
						var status = true;
						for(var i in self.tableData){
							for(var a in data.data){
								if(self.tableData[i].appid == a){
									if(parseInt(data.data[a])>0){
										self.tableData[i].getinfonum = data.data[a];
									}else{
										self.tableData[i].getinfonum = 0;
									}
								}
							}
						}
						for(var x in self.tableData){
							var breal = false;
							for(var t in data.data){
								if(self.tableData[x].appid == t){
									if(parseInt(self.tableData[x].filenum) != parseInt(data.data[t])){
										status = false;
										breal = true;
										break;
									}
								}
							}
							if(breal){
								break;
							}
						}
						if(status){
							self.getinfonumNum = 0;
						}else{
							self.getinfonumtime();
						}
					},'json');
				},5000)
				
			},
			handleRefreshVal(type,appid){
				return {
					type:type,
					appid:appid
				}
			},
			handleRefreshClick(appid){
				this.handleRefresh({
					type:0,
					appid:appid
				});
			},
			handleRefresh(data){
				var self = this;
				var index = 0;
				var status = 0;
				for(var i in self.tableData){
					if(self.tableData[i].appid == data.appid){
						index = i;
						status = self.tableData[i].state
					}
				}
				if(status == 0 || status == 4 || status == -1){
					// if(!self.tableData[index]['time']){
						var param = {
							appid:data.appid,
						};
						if(parseInt(data.type)){
							param['force'] = 1;
						}
						self.tableData[index].state = 1;
						$.post(MOD_URL+'&op=initexport',param,function(json){
							if(json.error){
								self.tableData[index].state = status;
								self.$notify.error({
									title: '错误',
									message: json.error
								});
							}else{
								
								self.tableData[index].percent = 0;
								if(self.GetFetachAppids.indexOf(data.appid)<0){
									self.GetFetachAppids.push(data.appid);
								}
								if(self.GetFetachNum == 0){
									self.handleRefreshLoading();
								}
							}
						},'json');
						
					// }
				}
			},
			handleRefreshLoading(){
				var self = this;
				self.GetFetachNum++;
				if(!self.GetFetachAppids.length){
					self.GetFetachNum = 0;
					return false;
				}
				setTimeout(function(){
					if(!self.GetFetachAppids.length){
						self.GetFetachNum = 0;
						return false;
					}
					$.post(MOD_URL+'&op=library&operation=getexportstatus',{
						appids:self.GetFetachAppids.join(',')
					},function(json){
						for(var i in json.data){
							var item = json.data[i];
							for(var x in self.tableData){
								var xtem = self.tableData[x];
								// console.log(item.appid ,xtem.appid)
								if(item.appid == xtem.appid){
									if(parseInt(item.state)==4){
										xtem.filenum = item.filenum;
										xtem.percent = parseInt(item.percent);
										xtem.state = parseInt(item.state);
										if(self.GetFetachAppids.indexOf(xtem.appid)>-1){
											self.GetFetachAppids.splice(self.GetFetachAppids.indexOf(xtem.appid),1);
										}
										let appname = xtem.appname;
										setTimeout(function(){
											self.$message({
												type:'success',
												message:appname+'更新完成'
											},500);
										},500);
									}else if(parseInt(item.state)==-1){
										xtem.state = parseInt(item.state);
										if(self.GetFetachAppids.indexOf(xtem.appid)>-1){
											self.GetFetachAppids.splice(self.GetFetachAppids.indexOf(xtem.appid),1);
										}
										let appname = xtem.appname;
										setTimeout(function(){
											self.$message.error(appname+'更新失败');
										},500);
									}else{
										if(parseInt(item.state) != xtem.state){
											xtem.percent = 100;
										}
										xtem.filenum = item.filenum;
										xtem.percent = parseInt(item.percent);
										xtem.state = parseInt(item.state);
										if(parseInt(item.state)==0){
											if(self.GetFetachAppids.indexOf(xtem.appid)>-1){
												self.GetFetachAppids.splice(self.GetFetachAppids.indexOf(xtem.appid),1);
											}
											let appname = xtem.appname;
											setTimeout(function(){
												self.$message.error(appname+'更新中断，请刷新重试');
											},500);
										}
									}
									break;
								}
							}
						}
						self.$nextTick(function(){
							self.handleRefreshLoading();
						});
					},'json');
				},2000);
				
				
			},
			GetCatalogueSelect(){
				var self = this;
				$.post(MOD_URL+'&op=library&operation=getpath',{
					gettype:1
				},function(data){
					var fdata = data.data;
					self.catalogue.selectData = [];
					for(var i in fdata){
						if(fdata[i].type==1){
							var path = fdata[i].path.split('\\');
							self.catalogue.defaultVal = path;
							self.catalogue.gettype = fdata[i].type;
							var str = {
								path:path.join('/'),
								charset:fdata[i].charset,
								type:fdata[i].type,
							}
						}else{
							var str = {
								path:fdata[i].path,
								charset:fdata[i].charset,
								type:fdata[i].type,
							}
						}
						self.catalogue.selectData.push(str);
					}
					
				},'json');
			},
			handleavatar(type) {//头像点击
				switch(type){
					case 'personal':
						window.location.href = MOD_URL + '&op=user&do=personal';
					break;
					case 'help':
						window.open('https://www.yuque.com/pichome');
					break;
					case 'problem':
						window.open('https://support.qq.com/products/340252');
					break;
					case 'setting':
						window.location.href = MOD_URL + '&op=admin&do=authorize';
					break;
					case 'library':
						window.location.href = MOD_URL + '&op=library';
					break;
					case 'about':
						this.$alert(
						`<div class="aboutlogo">
							<img src="`+MOD_PATH+`/image/phlogo.png" alt="">
						</div>
						<div class="aboutmessage">
							<div class="aboutlist">
								<span class="title">软件名称：</span><span class="mes">欧奥PicHome</span>
							</div>
							<div class="aboutlist">
								<span class="title">版本信息：</span><span class="mes">$_G[setting][version]</span>
							</div>
							<div class="aboutlist">
								<span class="title">版权信息：</span><span class="mes">Powered By oaooa PicHome © 2020-2022 欧奥图文</span>
							</div>
							<div class="aboutlist">
								<span class="title">网站地址：</span><span class="mes"><a class="address" href="https://oaooa.com/" target="_blank">oaooa.com</a></span>
							</div>
						</div>`,
						'',
						{
							customClass:'aboutPichome',
							showClose:false,
							showConfirmButton:false,
							dangerouslyUseHTMLString: true,
							closeOnClickModal:true
						});
					break;
					case 'OutLogin':
						this.$confirm('您确定要注销登录?', '提示', {
						          confirmButtonText: '确定',
						          cancelButtonText: '取消',
						          type: 'warning'
						        }).then(function() {
						         jQuery.get('user.php?mod=login&op=logging&action=logout&formhash={FORMHASH}&t='+new Date().getTime(),function(data){
						         		window.location.reload();
						         	});
						        }).catch(function() {
						                   
						        });
					break;
					case 'system':
						window.open(SITEURL+'admin.php?mod=system');
					break;
				}
				
			},
		},
		mounted() {
			
		}
	})
</script>

<!--{template pc/frame/footer_simple}-->
